package com.atguigu.util

import java.util.Properties

import org.apache.kafka.clients.producer.KafkaProducer

/**
 * description ：kafka 工具类
 * author      ：剧情再美终是戏 
 * mail        : 13286520398@163.com
 * date        ：Created in 2020/3/11 14:43
 * modified By ：
 * version:    : 1.0
 */
object KafkaUtil {

  /**
   * 获取 kafka生产者
   *
   * @Author 剧情再美终是戏
   * @Date 2020/3/11 14:52
   * @param bootstapServers kafka borker实例
   * @return org.apache.kafka.clients.producer.KafkaProducer<java.lang.String,java.lang.String>
   * @Version 1.0
   **/
  def getKafkaProducer(bootstapServers: String) = {
    val props = new Properties()
    props.put("bootstrap.servers", bootstapServers)
    props.put("acks", "-1")
    props.put("batch.size", "16384")
    props.put("linger.ms", "10")
    props.put("buffer.memory", "33554432")
    props.put("key.serializer",
      "org.apache.kafka.common.serialization.StringSerializer")
    props.put("value.serializer",
      "org.apache.kafka.common.serialization.StringSerializer")
    new KafkaProducer[String, String](props)
  }
}
